function InputAssetSubCategory(){	
	
	var status;
	if (Ext.getCmp('active_subcategory').getValue() == true)
		status = 'true';
	else 
		status = 'false';
	
	
	var ScId = Ext.getCmp('ScId').getValue();
	var CatId = Ext.getCmp('CategoryId').getValue();
	var Cat = Ext.getCmp('Category').getValue();
	var SubCat = Ext.getCmp('SubCategory').getValue();
		
	if(Ext.getCmp('Category').getValue() == null || Ext.getCmp('Category').getValue() == "") {
		Ext.MessageBox.show({
		 	title: 'WARNING!',
	        msg: 'Field Category Required',
	        icon: Ext.Msg.WARNING
	    });
	} else if(Ext.getCmp('SubCategory').getValue() == null || Ext.getCmp('SubCategory').getValue() == "") {
		Ext.MessageBox.show({
		 	title: 'WARNING!',
	        msg: 'Field SubCategory Required',
	        icon: Ext.Msg.WARNING
	    });
	} else {
		var data = {SC_ID: ScId, CATEGORY_ID: CatId, CATEGORY: Cat, SUB_CATEGORY: SubCat, ACTIVE:status, USER:""};
		
		if (Ext.getCmp('ButtonAddSubCategory').getText()=="Add SC"){
			 var url  = './Services/DataMaster/AssetSubCategory/Add';
			 PostData(data,url,"Insert");
		}else{
			 var url  = './Services/DataMaster/AssetSubCategory/Update';
			 PostData(data,url,"Update");
		}                                           
		
		Ext.getCmp('ButtonAddSubCategory').setText("Add SC");
		emptyAssetSubCategory();                                                      
		Ext.getStore('Administration.AssetSubCategory').load();
		Ext.getStore('AssetDataMaster.SubCategory').load();
	}

}

function emptyAssetSubCategory(){
	Ext.getCmp('ButtonAddSubCategory').setText('Add SC');
	Ext.getCmp('ButtonAddBrand').setDisabled(true);
	Ext.getCmp('ScId').setValue("");
	Ext.getCmp('SubCategory').setValue("");
	Ext.getCmp('active_subcategory').setValue(true);	
}

function SearchAssetCategorySub(){
	var keyword = Ext.getCmp("keywordCategorySub").getValue();
	Ext.getStore('Administration.AssetCategorySub').getProxy().url = "./Services/DataMaster/AssetCategory/List?keyword="+keyword+"";
	Ext.getStore('Administration.AssetCategorySub').load();
}

function DeleteAssetSubCategory(){
	var rec = Ext.getCmp('table_assetSubCategory').getSelectionModel().getSelection();
	if (rec.length>0){
		  Ext.MessageBox.confirm('Delete', 'Are you sure ?', function(btn) {
		        if (btn === 'yes') {
		        	 for (var i = 0; i<rec.length ; i++){
		     	    	var id = rec[i].get('SC_ID');
		     	    	var data = {SC_ID: id};
		     	    	var url  = './Services/DataMaster/AssetSubCategory/Delete';
		     	    	PostData(data,url,"Delete");
		     	    }
		         RefreshAssetSubCategory();
		        
		        }
		    });
	}else{
    	Ext.MessageBox.show({
		 	title: 'WARNING!',
	        msg: 'No Data Selected',
	        icon: Ext.Msg.WARNING
	    });	
    }
}


function getValueGridAssetSubCategory0(record){
	Ext.getCmp("Category").setDisabled(true);
	Ext.getCmp("CategoryId").setDisabled(true);
	Ext.getCmp("ScId").setDisabled(true);
	Ext.getCmp("ButtonAddBrand").setDisabled(true);
	Ext.getCmp("ButtonClearSubCategory").setDisabled(true);
    Ext.getCmp('CategoryId').setValue(record.get('CATEGORY_ID'));
    Ext.getCmp('Category').setValue(record.get('CATEGORY'));
    SearchAssetSubCategory();
}

function getValueGridAssetSubCategory(record){
	Ext.getCmp("Category").setDisabled(true);
	Ext.getCmp("ButtonAddBrand").setDisabled(false);
	Ext.getCmp("ButtonClearSubCategory").setDisabled(false);
	Ext.getCmp('ButtonAddSubCategory').setText('Update SC');
    Ext.getCmp('ScId').setValue(record.get('SC_ID'));
    Ext.getCmp('SubCategory').setValue(record.get('SUB_CATEGORY'));
    if (record.get('ACTIVE')=="true"){
    	Ext.getCmp('active_subcategory').setValue(true);
    }else{
    	Ext.getCmp('inactive_subcategory').setValue(true);
    }  
}

function SearchAssetSubCategory(){
	var categoryId = Ext.getCmp("CategoryId").getValue();
	var keyword = Ext.getCmp("keywordSubCategory").getValue();
	Ext.getStore('Administration.AssetSubCategory').getProxy().url = "./Services/DataMaster/AssetSubCategory/List?CATEGORY_ID="+categoryId+"&keyword="+keyword+"";
	Ext.getStore('Administration.AssetSubCategory').load();	
}

function RefreshAssetSubCategory(){
	Ext.getCmp('keywordSubCategory').setValue("");
	SearchAssetSubCategory();
}
